package com.ctesi.task.hubei;

import com.ctesi.service.zhaobiao.JiangSu.JiangSuProcessorService;
import com.ctesi.service.zhaobiao.anhui.AnHuiProcessorService;
import com.ctesi.service.zhaobiao.fujian.FuJianProcessorService;
import com.ctesi.service.zhaobiao.guangdong.GuangDongProcessorService;
import com.ctesi.service.zhaobiao.guangxi.GuangXiProcessorService;
import com.ctesi.service.zhaobiao.hubei.HuBeiProcessorService;
import com.ctesi.service.zhaobiao.hunan.ChangShaProcessorService;

import com.ctesi.service.zhaobiao.hunan.ZhuZhouProcessorService;
import com.ctesi.service.zhaobiao.jiangxi.JiangXiProcessorService;
import com.ctesi.service.zhaobiaopipelineService;
import com.ctesi.service.zhaobiao.shandong.ShanDongProcessorService;
import com.ctesi.service.zhaobiao.shanghai.ShangHaiProcessorService;
import com.ctesi.service.zhaobiao.zhejiang.ZheJiangProcessorService;
import com.ctesi.service.zhongbiao.HuBeizhongbiaoProcessorService;
import com.ctesi.service.zhongbiaopipelineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.model.HttpRequestBody;
import us.codecraft.webmagic.utils.HttpConstant;

import java.nio.charset.StandardCharsets;


@Component
public class Task {

    //注入相关的数据处理的pipeline
    @Autowired
    private zhaobiaopipelineService zhaobiaopipelineService;

    @Autowired
    private AnHuiProcessorService anHuiProcessorService;

    @Autowired
    private GuangXiProcessorService guangXiProcessorService;

    @Autowired
    private FuJianProcessorService fuJianProcessorService;

    @Autowired
    private ChangShaProcessorService changShaProcessorService;

    @Autowired
    private ZhuZhouProcessorService zhuZhouProcessorService;

    @Autowired
    private ZheJiangProcessorService zheJiangProcessorService;

    @Autowired
    private JiangSuProcessorService jiangSuProcessorService;

    @Autowired
    private ShanDongProcessorService shanDongProcessorService;

    @Autowired
    private JiangXiProcessorService jiangXiProcessorService;

    @Autowired
    private ShangHaiProcessorService shangHaiProcessorService;

    @Autowired
    private GuangDongProcessorService guangDongProcessorService;

    @Autowired
    private HuBeizhongbiaoProcessorService huBeizhongbiaoProcessorService;

    @Autowired
    private zhongbiaopipelineService zhongbiaopipelineService;

    @Autowired HuBeiProcessorService huBeiProcessorService;

    //湖北省招标任务
    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void Hubei() {
//        //1. 房建市政
//        System.out.println("------------开始湖北省房建市政招标内容爬取任务-------------");
//        Spider HouseSpider = new Spider(new HuBeiProcessorService());
//        for (int i = 1; i <= 81; i++) {
//            if (i == 1) {
//                HouseSpider.addUrl("http://www.hbbidcloud.cn/hubei/jyxx/004002/004002001/about.html");
//            }
//            HouseSpider.addUrl(String.format("http://www.hbbidcloud.cn/hubei/jyxx/004002/004002001/%d.html", i));
//        }
//        HouseSpider.addPipeline(pipelineService);
//
//        HouseSpider.run();

//        //2. 水利工程
//        System.out.println("------------开始湖北省水利工程招标内容爬取任务-------------");
//        Spider WaterSpider = Spider.create(new HuBeiProcessorService());
//        for (int i = 1; i <= 18; i++) {
//            if (i == 1) {
//                WaterSpider.addUrl("http://www.hbbidcloud.cn/hubei/jyxx/004002/004002002/about.html");
//            }
//            WaterSpider.addUrl(String.format("http://www.hbbidcloud.cn/hubei/jyxx/004002/004002002/%d.html", i));
//        }
//        WaterSpider.addPipeline(pipelineService);
//        WaterSpider.run();

        //3. 交通工程
        System.out.println("------------开始湖北省交通工程招标内容爬取任务-------------");
        Spider trafficSpider = Spider.create(huBeiProcessorService);
        for (int i = 1; i <= 11; i++) {
            if (i == 1) {
                trafficSpider.addUrl("http://www.hbbidcloud.cn/hubei/jyxx/004002/004002003/about.html");
            }
            trafficSpider.addUrl(String.format("http://www.hbbidcloud.cn/hubei/jyxx/004002/004002003/%d.html", i));
        }
        trafficSpider.addPipeline(zhaobiaopipelineService);
        trafficSpider.run();

        System.out.println("------------开始湖北省交通工程中标内容爬取任务-------------");
        Spider traffic1Spider = Spider.create(huBeizhongbiaoProcessorService);
        for (int i = 1; i <= 20; i++) {
            if (i == 1) {
                traffic1Spider.addUrl("http://www.hbbidcloud.cn/hubei/jyxx/004004/004004003/about.html");
            }
            traffic1Spider.addUrl(String.format("http://www.hbbidcloud.cn/hubei/jyxx/004004/004004003/%d.html", i));
        }
        traffic1Spider.addPipeline(zhongbiaopipelineService);
        traffic1Spider.run();



    }

    //长江市招标任务
//    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void ChangSha() {

        //1. 房建市政
        System.out.println("------------开始长沙市的房建市政爬取任务------------------");
        Spider houseSpider = new Spider(new ChangShaProcessorService());
        for (int i = 1; i <= 2; i++) {
            //83
            if (i == 1) {
                houseSpider.addUrl("https://fwpt.csggzy.cn/jyxxfjzbgg/index.jhtml");
            } else {
                houseSpider.addUrl(String.format("https://fwpt.csggzy.cn/jyxxfjzbgg/index_%d.jhtml", i));
            }
        }
        houseSpider.addPipeline(zhaobiaopipelineService);
        houseSpider.run();


        //2. 水利工程
        System.out.println("------------开始长沙市的水利工程爬取任务------------------");
        Spider waterSpider = new Spider(new ChangShaProcessorService());
        for (int i = 1; i <= 3; i++) {
            if (i == 1) {
                waterSpider.addUrl("https://fwpt.csggzy.cn/jyxxslzbgg/index.jhtml");
            } else {
                waterSpider.addUrl(String.format("https://fwpt.csggzy.cn/jyxxslzbgg/index_%d.jhtml", i));
            }
        }
        waterSpider.addPipeline(zhaobiaopipelineService);
        waterSpider.run();

        //3. 交通工程
        System.out.println("------------开始长沙市的交通工程爬取任务------------------");
        Spider trafficSpider = new Spider(new ChangShaProcessorService());
        for (int i = 1; i <= 3; i++) {
            if (i == 1) {
                trafficSpider.addUrl("https://fwpt.csggzy.cn/jyxxjtzbgg/index.jhtml");
            } else {
                trafficSpider.addUrl(String.format("https://fwpt.csggzy.cn/jyxxjtzbgg/index_%d.jhtml", i));
            }
        }
        trafficSpider.addPipeline(zhaobiaopipelineService);
        trafficSpider.run();

    }


    //株洲市招标任务
//    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void ZhuZhou() {
        //1. 房建市政
        Spider houseSpider = new Spider(new ZhuZhouProcessorService());

        for (int i = 1; i <= 6; i++) {
            houseSpider.addUrl(String.format("http://www.zzzyjy.cn/016/016001/016001001/%d.html", i));
        }
        houseSpider.addPipeline(zhaobiaopipelineService);
        houseSpider.run();

        //2. 水利工程
        Spider waterSpider = new Spider(new ZhuZhouProcessorService());
        for (int i = 1; i <= 3; i++) {
            waterSpider.addUrl(String.format("http://www.zzzyjy.cn/016/016004/016004001/%d.html", i));
        }
        waterSpider.addPipeline(zhaobiaopipelineService);
        waterSpider.run();

        //3. 交通工程
        Spider trafficSpider = new Spider(new ZhuZhouProcessorService());
        for (int i = 1; i <= 2; i++) {
            trafficSpider.addUrl(String.format("http://www.zzzyjy.cn/016/016003/016003001/%d.html", i));
            trafficSpider.addPipeline(zhaobiaopipelineService);
            trafficSpider.run();
        }

    }


    //浙江省招标任务
//    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void ZheJiang() {

        Spider spider = new Spider(new ZheJiangProcessorService());
        // 创建一个自定义请求体
        int pn = 0;
        for (int i = 1; i <= 1; i++) {
            Request request = new Request("http://zjpubservice.zjzwfw.gov.cn/inteligentsearch/rest/inteligentSearch/getFullTextData");
            request.setMethod(HttpConstant.Method.POST);
            String params = String.format("{\"token\":\"\",\"pn\":%d,\"rn\":12,\"sdt\":\"\",\"edt\":\"\",\"wd\":\"\",\"inc_wd\":\"\",\"exc_wd\":\"\",\"fields\":\"title\",\"cnum\":\"001\",\"sort\":\"{\\\"webdate\\\":\\\"0\\\"}\",\"ssort\":\"title\",\"cl\":200,\"terminal\":\"\",\"condition\":[{\"fieldName\":\"categorynum\",\"isLike\":true,\"likeType\":2,\"equal\":\"002001001\"},{\"fieldName\":\"infoc\",\"isLike\":true,\"likeType\":2,\"equal\":\"33\"}],\"time\":[{\"fieldName\":\"webdate\",\"startTime\":\"2023-1-1 00:00:00\",\"endTime\":\"2023-9-1 23:59:59\"}],\"highlights\":\"\",\"statistics\":null,\"unionCondition\":null,\"accuracy\":\"\",\"noParticiple\":\"0\",\"searchRange\":null,\"isBusiness\":\"1\"}", pn);
            pn = pn + 12;
            request.setRequestBody(HttpRequestBody.json(params, "utf-8"));
            spider.addRequest(request);
        }
        spider.addPipeline(zhaobiaopipelineService);
        spider.run();


    }

    //福建省招标任务
//    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void FuJian() {

        //1. 房建市政
        Spider houseSpider = new Spider(new FuJianProcessorService());
        // 创建一个自定义请求体
        for (int i = 1; i <= 84; i++) {
            Request houseRequest = new Request("https://ggzyfw.fj.gov.cn/FwPortalApi/Trade/TradeInfo");
            houseRequest.setMethod(HttpConstant.Method.POST);

            String houseParams = String.format("{\"pageNo\":%d,\"pageSize\":20,\"AREACODE\":\"\",\"M_PROJECT_TYPE\":\"\",\"KIND\":\"GCJS\",\"GGTYPE\":\"1\",\"PROTYPE\":\"A01\",\"timeType\":\"\",\"BeginTime\":\"2023-01-01 00:00:00\",\"EndTime\":\"2023-09-01 23:59:59\",\"createTime\":[\"2023-01-01 00:00:00\",\"2023-09-01 23:59:59\"]}", i);
            houseRequest.setRequestBody(HttpRequestBody.json(houseParams, "utf-8"));
            houseSpider.addRequest(houseRequest);
        }
        houseSpider.run();


        //2. 水利工程
        Spider waterSpider = new Spider(new FuJianProcessorService());
        // 创建一个自定义请求体
        for (int i = 1; i <= 27; i++) {
            Request waterRequest = new Request("https://ggzyfw.fj.gov.cn/FwPortalApi/Trade/TradeInfo");
            waterRequest.setMethod(HttpConstant.Method.POST);
            String waterParams = String.format("{\"pageNo\":%d,\"pageSize\":20,\"AREACODE\":\"\",\"M_PROJECT_TYPE\":\"\",\"KIND\":\"GCJS\",\"GGTYPE\":\"1\",\"PROTYPE\":\"A07\",\"timeType\":\"\",\"BeginTime\":\"2023-01-01 00:00:00\",\"EndTime\":\"2023-09-01 23:59:59\",\"createTime\":[\"2023-01-01 00:00:00\",\"2023-09-01 23:59:59\"]}", i);
            waterRequest.setRequestBody(HttpRequestBody.json(waterParams, "utf-8"));
            houseSpider.addRequest(waterRequest);
        }
        waterSpider.run();

        //3.交通工程
        Spider trafficSpider = new Spider(new FuJianProcessorService());
        // 创建一个自定义请求体
        for (int i = 1; i <= 20; i++) {
            Request trafficRequest = new Request("https://ggzyfw.fj.gov.cn/FwPortalApi/Trade/TradeInfo");
            trafficRequest.setMethod(HttpConstant.Method.POST);
            String trafficParams = String.format("{\"pageNo\":%d,\"pageSize\":20,\"AREACODE\":\"\",\"M_PROJECT_TYPE\":\"\",\"KIND\":\"GCJS\",\"GGTYPE\":\"1\",\"PROTYPE\":\"A03\",\"timeType\":\"\",\"BeginTime\":\"2023-01-01 00:00:00\",\"EndTime\":\"2023-09-01 23:59:59\",\"createTime\":[\"2023-01-01 00:00:00\",\"2023-09-01 23:59:59\"]}", i);
            trafficRequest.setRequestBody(HttpRequestBody.json(trafficParams, "utf-8"));
            trafficSpider.addRequest(trafficRequest);
        }
        trafficSpider.run();


    }

    //江苏省招标任务
//    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void JiangSu() {
        //1. 房建市政
        Spider houseSpider = new Spider(new JiangSuProcessorService());
        // 创建一个自定义请求体
        int pn = 0;
        for (int i = 1; i <= 36; i++) {
            Request houseRequest = new Request("http://jsggzy.jszwfw.gov.cn/inteligentsearch/rest/esinteligentsearch/getFullTextDataNew");
            houseRequest.setMethod(HttpConstant.Method.POST);

            String houseParams = String.format("{\"token\":\"\",\"pn\":%d,\"rn\":20,\"sdt\":\"\",\"edt\":\"\",\"wd\":\"\",\"inc_wd\":\"\",\"exc_wd\":\"\",\"fields\":\"title\",\"cnum\":\"001\",\"sort\":\"{\\\"infodatepx\\\":\\\"0\\\"}\",\"ssort\":\"title\",\"cl\":200,\"terminal\":\"\",\"condition\":[{\"fieldName\":\"categorynum\",\"isLike\":true,\"likeType\":2,\"equal\":\"003001001\"}],\"time\":[{\"fieldName\":\"infodatepx\",\"startTime\":\"2023-08-01 00:00:00\",\"endTime\":\"2023-08-17 23:59:59\"}],\"highlights\":\"title\",\"statistics\":null,\"unionCondition\":null,\"accuracy\":\"\",\"noParticiple\":\"1\",\"searchRange\":null,\"isBusiness\":\"1\"}", i);
            houseRequest.setRequestBody(HttpRequestBody.json(houseParams, "utf-8"));
            houseSpider.addRequest(houseRequest);
            pn = pn + 20;
        }
        houseSpider.run();

        //2. 交通工程
        Spider trafficSpider = new Spider(new JiangSuProcessorService());
        // 创建一个自定义请求体
        int tpn = 0;
        for (int i = 1; i <= 50; i++) {
            Request trafficRequest = new Request("http://jsggzy.jszwfw.gov.cn/inteligentsearch/rest/esinteligentsearch/getFullTextDataNew");
            trafficRequest.setMethod(HttpConstant.Method.POST);

            String trafficParams = String.format("{\"token\":\"\",\"pn\":%d,\"rn\":20,\"sdt\":\"\",\"edt\":\"\",\"wd\":\"\",\"inc_wd\":\"\",\"exc_wd\":\"\",\"fields\":\"title\",\"cnum\":\"001\",\"sort\":\"{\\\"infodatepx\\\":\\\"0\\\"}\",\"ssort\":\"title\",\"cl\":200,\"terminal\":\"\",\"condition\":[{\"fieldName\":\"categorynum\",\"isLike\":true,\"likeType\":2,\"equal\":\"003002001\"}],\"time\":[{\"fieldName\":\"infodatepx\",\"startTime\":\"2023-05-17 00:00:00\",\"endTime\":\"2023-08-17 23:59:59\"}],\"highlights\":\"title\",\"statistics\":null,\"unionCondition\":null,\"accuracy\":\"\",\"noParticiple\":\"1\",\"searchRange\":null,\"isBusiness\":\"1\"}", tpn);
            trafficRequest.setRequestBody(HttpRequestBody.json(trafficParams, "utf-8"));
            trafficSpider.addRequest(trafficRequest);
            tpn = tpn + 20;
        }
        trafficSpider.run();

        //3. 水利工程
        Spider waterSpider = new Spider(new JiangSuProcessorService());
        // 创建一个自定义请求体
        int wpn = 0;
        for (int i = 1; i <= 50; i++) {
            Request waterRequest = new Request("http://jsggzy.jszwfw.gov.cn/inteligentsearch/rest/esinteligentsearch/getFullTextDataNew");
            waterRequest.setMethod(HttpConstant.Method.POST);
            String waterParams = String.format("{\"token\":\"\",\"pn\":%d,\"rn\":20,\"sdt\":\"\",\"edt\":\"\",\"wd\":\"\",\"inc_wd\":\"\",\"exc_wd\":\"\",\"fields\":\"title\",\"cnum\":\"001\",\"sort\":\"{\\\"infodatepx\\\":\\\"0\\\"}\",\"ssort\":\"title\",\"cl\":200,\"terminal\":\"\",\"condition\":[{\"fieldName\":\"categorynum\",\"isLike\":true,\"likeType\":2,\"equal\":\"003002001\"}],\"time\":[{\"fieldName\":\"infodatepx\",\"startTime\":\"2023-05-17 00:00:00\",\"endTime\":\"2023-08-17 23:59:59\"}],\"highlights\":\"title\",\"statistics\":null,\"unionCondition\":null,\"accuracy\":\"\",\"noParticiple\":\"1\",\"searchRange\":null,\"isBusiness\":\"1\"}", wpn);
            waterRequest.setRequestBody(HttpRequestBody.json(waterParams, "utf-8"));
            waterSpider.addRequest(waterRequest);
            wpn = wpn + 20;
        }
        waterSpider.run();

    }

    //山东省招标任务
//    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void ShanDong() {
        //1. 房建市政
        Spider houseSpider = new Spider(new ShanDongProcessorService());
        for (int i = 1; i <= 27; i++) {
            houseSpider.addUrl(String.format("http://www.sdsggzyjyzx.gov.cn/col/col209898/index.html?uid=474655&pageNum=%d", i));
        }
        houseSpider.addPipeline(zhaobiaopipelineService);
        houseSpider.run();

        //2.交通工程
        Spider trafficSpider = new Spider(new ShanDongProcessorService());
        for (int i = 1; i <= 67; i++) {
            trafficSpider.addUrl(String.format("http://www.sdsggzyjyzx.gov.cn/col/col209904/index.html?uid=474655&pageNum=%d", i));
        }
        trafficSpider.addPipeline(zhaobiaopipelineService);
        trafficSpider.run();

        //3.水利工程
        Spider waterSpider = new Spider(new ShanDongProcessorService());
        for (int i = 1; i <= 72; i++) {
            waterSpider.addUrl(String.format("http://www.sdsggzyjyzx.gov.cn/col/col209904/index.html?uid=474655&pageNum=%d", i));
        }
        waterSpider.addPipeline(zhaobiaopipelineService);
        waterSpider.run();

    }

    //广西省招标任务
//    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void Guangxi() {
        //1. 房建市政-3
        Spider houseSpider = new Spider(guangXiProcessorService);
        for (int i = 1; i <= 1; i++) {
            houseSpider.addUrl("http://gxggzy.gxzf.gov.cn/igs/front/search/list.html?&filter%5BDOCTITLE%5D=" + String.format("&pageNumber=%d", i) + "&pageSize=10&index=gxggzy_jyfw&type=jyfw&filter%5Bparentparentid%5D=84165&filter%5Bparentchnldesc%5D=%E6%88%BF%E5%BB%BA%E5%B8%82%E6%94%BF&filter%5Bchnldesc%5D=%E6%8B%9B%E6%A0%87%E5%85%AC%E5%91%8A&filter%5BSITEID%5D=234&orderProperty=PUBDATE&orderDirection=desc&filter%5BAVAILABLE%5D=true");
        }
        houseSpider.addPipeline(zhaobiaopipelineService);
        guangXiProcessorService.setBidType("房建市政");
        houseSpider.run();

        //2.交通工程- 18
        Spider trafficSpider = new Spider(guangXiProcessorService);
        for (int i = 1; i <= 1; i++) {
            trafficSpider.addUrl("http://gxggzy.gxzf.gov.cn/igs/front/search/list.html?&filter%5BDOCTITLE%5D=&" + String.format("pageNum=%d", i) + "&pageSize=10&index=gxggzy_jyfw&type=jyfw&filter%5Bparentparentid%5D=84165&filter%5Bparentchnldesc%5D=%E4%BA%A4%E9%80%9A%E5%B7%A5%E7%A8%8B&filter%5Bchnldesc%5D=%E4%BA%A4%E6%98%93%E5%85%AC%E5%91%8A&filter%5BSITEID%5D=234&orderProperty=PUBDATE&orderDirection=desc&filter%5BAVAILABLE%5D=true");
        }
//        trafficSpider.addPipeline(pipelineService);
        guangXiProcessorService.setBidType("交通工程");
        trafficSpider.run();

        //3.水利工程 - 6
        Spider waterSpider = new Spider(guangXiProcessorService);
        for (int i = 1; i <= 1; i++) {
            waterSpider.addUrl("http://gxggzy.gxzf.gov.cn/igs/front/search/list.html?&filter%5BDOCTITLE%5D=&" + String.format("pageNum=%d", i) + "&pageSize=10&index=gxggzy_jyfw&type=jyfw&filter%5Bparentparentid%5D=84165&filter%5Bparentchnldesc%5D=%E6%B0%B4%E5%88%A9%E5%B7%A5%E7%A8%8B&filter%5Bchnldesc%5D=%E4%BA%A4%E6%98%93%E5%85%AC%E5%91%8A&filter%5BSITEID%5D=234&orderProperty=PUBDATE&orderDirection=desc&filter%5BAVAILABLE%5D=true");
        }
//        waterSpider.addPipeline(pipelineService);
        guangXiProcessorService.setBidType("水利工程");
        waterSpider.run();

    }

    //江西省招标任务
    public void JiangXi() {
        //1. 房建市政
        Spider houseSpider = new Spider(new JiangXiProcessorService());
        int hpn = 0;
        for (int i = 1; i <= 493; i++) {
            Request houseRequest = new Request("https://www.jxsggzy.cn/XZinterface/rest/esinteligentsearch/getFullTextDataNew");
            houseRequest.setMethod(HttpConstant.Method.POST);
            String houseParams = String.format("{\"token\":\"\",\"pn\":%d,\"rn\":10,\"sdt\":\"\",\"edt\":\"\",\"wd\":\"\",\"inc_wd\":\"\",\"exc_wd\":\"\",\"fields\":\"\",\"cnum\":\"\",\"sort\":\"{\\\"webdate\\\":\\\"0\\\",\\\"id\\\":\\\"0\\\"}\",\"ssort\":\"\",\"cl\":10000,\"terminal\":\"\",\"condition\":[{\"fieldName\":\"categorynum\",\"equal\":\"002001001\",\"notEqual\":null,\"equalList\":null,\"notEqualList\":null,\"isLike\":true,\"likeType\":2}],\"time\":[{\"fieldName\":\"webdate\",\"startTime\":\"2023-01-01 00:00:00\",\"endTime\":\"2023-09-01 23:59:59\"}],\"highlights\":\"\",\"statistics\":null,\"unionCondition\":[],\"accuracy\":\"\",\"noParticiple\":\"1\",\"searchRange\":null,\"noWd\":true}", hpn);
            houseRequest.setRequestBody(HttpRequestBody.json(houseParams, "utf-8"));
            houseSpider.addRequest(houseRequest);
            hpn = hpn + 10;
        }
        houseSpider.addPipeline(zhaobiaopipelineService);
        houseSpider.run();

        //2. 水利工程
        Spider waterSpider = new Spider(new JiangXiProcessorService());
        int wpn = 0;
        for (int i = 1; i <= 61; i++) {
            Request waterRequest = new Request("https://www.jxsggzy.cn/XZinterface/rest/esinteligentsearch/getFullTextDataNew");
            waterRequest.setMethod(HttpConstant.Method.POST);
            String waterParams = String.format("{\"token\":\"\",\"pn\":%d,\"rn\":10,\"sdt\":\"\",\"edt\":\"\",\"wd\":\"\",\"inc_wd\":\"\",\"exc_wd\":\"\",\"fields\":\"\",\"cnum\":\"\",\"sort\":\"{\\\"webdate\\\":\\\"0\\\",\\\"id\\\":\\\"0\\\"}\",\"ssort\":\"\",\"cl\":10000,\"terminal\":\"\",\"condition\":[{\"fieldName\":\"categorynum\",\"equal\":\"002003001\",\"notEqual\":null,\"equalList\":null,\"notEqualList\":null,\"isLike\":true,\"likeType\":2}],\"time\":[{\"fieldName\":\"webdate\",\"startTime\":\"2023-01-01 00:00:00\",\"endTime\":\"2023-09-01 23:59:59\"}],\"highlights\":\"\",\"statistics\":null,\"unionCondition\":[],\"accuracy\":\"\",\"noParticiple\":\"1\",\"searchRange\":null,\"noWd\":true}", wpn);
            waterRequest.setRequestBody(HttpRequestBody.json(waterParams, "utf-8"));
            waterSpider.addRequest(waterRequest);
            wpn = wpn + 10;
        }
        waterSpider.addPipeline(zhaobiaopipelineService);
        waterSpider.run();

        //3.交通工程
        Spider trafficSpider = new Spider(new JiangXiProcessorService());
        int tpn = 0;
        for (int i = 1; i <= 61; i++) {
            Request trafficRequest = new Request("https://www.jxsggzy.cn/XZinterface/rest/esinteligentsearch/getFullTextDataNew");
            trafficRequest.setMethod(HttpConstant.Method.POST);
            String trafficParams = String.format("{\"token\":\"\",\"pn\":%d,\"rn\":10,\"sdt\":\"\",\"edt\":\"\",\"wd\":\"\",\"inc_wd\":\"\",\"exc_wd\":\"\",\"fields\":\"\",\"cnum\":\"\",\"sort\":\"{\\\"webdate\\\":\\\"0\\\",\\\"id\\\":\\\"0\\\"}\",\"ssort\":\"\",\"cl\":10000,\"terminal\":\"\",\"condition\":[{\"fieldName\":\"categorynum\",\"equal\":\"002003001\",\"notEqual\":null,\"equalList\":null,\"notEqualList\":null,\"isLike\":true,\"likeType\":2}],\"time\":[{\"fieldName\":\"webdate\",\"startTime\":\"2023-01-01 00:00:00\",\"endTime\":\"2023-09-01 23:59:59\"}],\"highlights\":\"\",\"statistics\":null,\"unionCondition\":[],\"accuracy\":\"\",\"noParticiple\":\"1\",\"searchRange\":null,\"noWd\":true}", tpn);
            trafficRequest.setRequestBody(HttpRequestBody.json(trafficParams, "utf-8"));
            trafficSpider.addRequest(trafficRequest);
            tpn = tpn + 10;
        }
        trafficSpider.addPipeline(zhaobiaopipelineService);
        trafficSpider.run();


    }

    //安徽省招标任务
//    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void AnHui() {
        //1. 房建市政670
        Spider houseSpider = new Spider(anHuiProcessorService);
        int hpn = 0;
        for (int i = 1; i <= 670; i++) {
            Request houseRequest = new Request("https://ggzy.ah.gov.cn/jsgc/list");
            houseRequest.setMethod(HttpConstant.Method.POST);
            String houseParams = String.format("currentPage=%d&tenderProjectType=A01&bulletinNature=1&jyptId=&region=", i);  //urlencode参数
            byte[] houseParamsBytes = houseParams.getBytes(StandardCharsets.UTF_8);    //转成字节数组
            houseRequest.setRequestBody(HttpRequestBody.custom(houseParamsBytes, "application/x-www-form-urlencoded", "UTF-8"));
            houseSpider.addRequest(houseRequest);
            hpn = hpn + 10;
        }
//        houseSpider.addPipeline(pipelineService);
        System.out.println("------------房建市政----------------");
        anHuiProcessorService.setBidType("房建市政");
        houseSpider.run();

        //2. 水利工程
        Spider waterSpider = new Spider(anHuiProcessorService);
        int wpn = 0;
        for (int i = 1; i <= 111; i++) {
            Request waterRequest = new Request("https://ggzy.ah.gov.cn/jsgc/list");
            waterRequest.setMethod(HttpConstant.Method.POST);
            String waterParams = String.format("currentPage=%d&tenderProjectType=A07&bulletinNature=1&jyptId=&region=", i);
            byte[] waterParamsBytes = waterParams.getBytes(StandardCharsets.UTF_8);    //转成字节数组
            waterRequest.setRequestBody(HttpRequestBody.custom(waterParamsBytes, "application/x-www-form-urlencoded", "UTF-8"));
            waterSpider.addRequest(waterRequest);
            wpn = wpn + 10;
        }
        System.out.println("------------水利工程----------------");
        waterSpider.addPipeline(zhaobiaopipelineService);
        anHuiProcessorService.setBidType("水利工程");
        waterSpider.run();

        //3.交通工程
        Spider trafficSpider = new Spider(anHuiProcessorService);
        int tpn = 0;
        for (int i = 1; i <= 177; i++) {
            Request trafficRequest = new Request("https://ggzy.ah.gov.cn/jsgc/list");
            trafficRequest.setMethod(HttpConstant.Method.POST);
            String trafficParams = String.format("currentPage=%d&tenderProjectType=AAA&bulletinNature=1&jyptId=&region=", i);
            byte[] trafficParamsBytes = trafficParams.getBytes(StandardCharsets.UTF_8);    //转成字节数组
            trafficRequest.setRequestBody(HttpRequestBody.custom(trafficParamsBytes, "application/x-www-form-urlencoded", "UTF-8"));//设置urlencode参数
            trafficSpider.addRequest(trafficRequest);
            tpn = tpn + 10;
        }
        trafficSpider.addPipeline(zhaobiaopipelineService);
        anHuiProcessorService.setBidType("交通工程");
        trafficSpider.run();
    }


    //上海招标任务
    public void ShangHai() {
        //上海市没有分类
        Spider spider = new Spider(shangHaiProcessorService);
        Request request = new Request("https://ciac.zjw.sh.gov.cn/NetInterBidweb/GKTB/SgfbZbxx.aspx");
        for (int i = 0; i < 178; i++) {
            String postBody = String.format("dr_gglb=0&dr_szqx=&txt_beginTime=2023-01-01&txt_endTime=2023-09-01&DropDownList_page=%d&hdInputNum=%d&hdState=&",i );

        }
        spider.addPipeline(zhaobiaopipelineService);
        spider.run();
    }


    //广东招标任务
    public void GuangDong() {
        //1. 房建市政
        Spider houseSpider = new Spider(new GuangDongProcessorService());
        for (int i = 1; i <= 2120; i++) {
            Request houseRequest = new Request("https://ygp.gdzwfw.gov.cn/ggzy-portal/search/v2/items");
            houseRequest.setMethod(HttpConstant.Method.POST);
            String houseParams = String.format("{\"type\":\"trading-type\",\"openConvert\":false,\"keyword\":\"\",\"siteCode\":\"44\",\"secondType\":\"A\",\"tradingProcess\":\"2C14,2C16,2C71,2C72,2C73,2C81,503,504,514,515,516,517,3C14,3C15,3C71,3C72,3C73,3C81\",\"thirdType\":\"[]\",\"projectType\":\"A02,A01\",\"publishStartTime\":\"20230101000000\",\"publishEndTime\":\"20230901235959\",\"pageNo\":%d,\"pageSize\":10}", i);
            houseRequest.setRequestBody(HttpRequestBody.json(houseParams, "utf-8"));
            houseSpider.addRequest(houseRequest);
        }
        houseSpider.addPipeline(zhaobiaopipelineService);
        houseSpider.run();

        //2. 水利工程
        Spider waterSpider = new Spider(new GuangDongProcessorService());
        for (int i = 1; i <= 417; i++) {
            Request waterRequest = new Request("https://ygp.gdzwfw.gov.cn/ggzy-portal/search/v2/items");
            waterRequest.setMethod(HttpConstant.Method.POST);
            String waterParams = String.format("{\"type\":\"trading-type\",\"openConvert\":false,\"keyword\":\"\",\"siteCode\":\"44\",\"secondType\":\"A\",\"tradingProcess\":\"2C14,2C16,2C71,2C72,2C73,2C81,503,504,514,515,516,517,3C14,3C15,3C71,3C72,3C73,3C81\",\"thirdType\":\"[]\",\"projectType\":\"A07\",\"publishStartTime\":\"20230101000000\",\"publishEndTime\":\"20230901235959\",\"pageNo\":%d,\"pageSize\":10}", i);
            waterRequest.setRequestBody(HttpRequestBody.json(waterParams, "utf-8"));
            waterSpider.addRequest(waterRequest);
        }
        waterSpider.addPipeline(zhaobiaopipelineService);
        waterSpider.run();

        //3.交通工程
        Spider trafficSpider = new Spider(new GuangDongProcessorService());
        for (int i = 1; i <= 352; i++) {
            Request trafficRequest = new Request("https://ygp.gdzwfw.gov.cn/ggzy-portal/search/v2/items");
            trafficRequest.setMethod(HttpConstant.Method.POST);
            String trafficParams = String.format("{\"type\":\"trading-type\",\"openConvert\":false,\"keyword\":\"\",\"siteCode\":\"44\",\"secondType\":\"A\",\"tradingProcess\":\"2C14,2C16,2C71,2C72,2C73,2C81,503,504,514,515,516,517,3C14,3C15,3C71,3C72,3C73,3C81\",\"thirdType\":\"[]\",\"projectType\":\"A03,A04,A05,A06,A10,A11\",\"publishStartTime\":\"20230101000000\",\"publishEndTime\":\"20230901235959\",\"pageNo\":%d,\"pageSize\":10}", i);
            trafficRequest.setRequestBody(HttpRequestBody.json(trafficParams, "utf-8"));
            trafficSpider.addRequest(trafficRequest);
        }
        trafficSpider.addPipeline(zhaobiaopipelineService);
        trafficSpider.run();

    }

}
